﻿Imports System.Data.Entity.Validation
Imports System
Imports System.Linq
Imports System.Security.Claims
Imports System.Web.UI

Public Class Register
    Inherits System.Web.UI.Page

    Protected Sub CreateUser(sender As Object, e As EventArgs)
        Dim userName_1 As String = UserName.Text
        Try
            Dim u As New User(userName_1) With { _
                 .UserName = userName_1 _
            }
            IdentityConfig.Users.Create(u)
            IdentityConfig.Secrets.Create(New UserSecret(userName_1, Password.Text))
            IdentityConfig.Logins.Add(New UserLogin(u.Id, IdentityConfig.LocalLoginProvider, userName_1))
            Context.SignIn(u.Id, New Claim() {}, isPersistent:=False)
            IdentityConfig.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
        Catch ex As DbEntityValidationException
            ErrorMessage.Text = ex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage
        End Try
    End Sub
End Class